#ifndef __REI_PID_H__
#define __REI_PID_H__


#include "stdint.h"

#pragma pack(1)

typedef struct
{
 float tag; //target value 目标值
 float cur; //current value     当前值
 float err; //err=tag-cur;      定义偏差值
 float last_err; //last_err=err; 定义上一个偏差值
 float prev_last_err; //prev_last_err=last_err;
 float kp; //proportion
 float ki; //integral
 float kd; //differential
 float integral_sum; //积分
 float integral_limit; //积分最大限制
 float output_limit; //输出最大限制

 float P_OUT;
 float I_OUT;
 float D_OUT;
 float output;//控制输出值
}pid_dat_t;

#pragma pack()

void pid_init (pid_dat_t* pid);
void pid_set_kp (pid_dat_t* pid,float kp);
void pid_set_ki (pid_dat_t* pid,float ki);
void pid_set_kd (pid_dat_t* pid,float kd);
void pid_set_tag (pid_dat_t* pid,float tag);
void pid_set_intergral_limit (pid_dat_t* pid,float integral_limit);
void pid_set_output_limit (pid_dat_t* pid,float output_limit);
void pid_reset_integral (pid_dat_t* pid);
float pid_calc (pid_dat_t *p_pid_dat, float cur_val);
float pid_get_err (pid_dat_t *p_pid_dat);
#endif // 
